home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / gfx / 3d / irit50src.lha / irit5 / grapdrvs / drawtsrf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-21  |  3.9 KB  |  105 lines

  1. /*****************************************************************************
  2. *   Default surface drawing routine common to graphics drivers.             *
  3. *                                         *
  4. * Written by:  Gershon Elber                Ver 0.1, June 1993.  *
  5. *****************************************************************************/
  6.  
  7. #include "irit_sm.h"
  8. #include "iritprsr.h"
  9. #include "allocate.h"
  10. #include "attribut.h"
  11. #include "cagd_lib.h"
  12. #include "symb_lib.h"
  13. #include "ip_cnvrt.h"
  14. #include "iritgrap.h"
  15.  
  16. /*****************************************************************************
  17. * DESCRIPTION:                                                               M
  18. * Draw a single trimmed surface object using current modes and             M
  19. * transformations.                                 M
  20. *   Piecewise linear approximation is cashed under "_isoline" and "_ctlmesh" M
  21. * attributes of PObj. Polygonal approximation is saved under "_polygons".    M
  22. *                                                                            *
  23. * PARAMETERS:                                                                M
  24. *   PObj:     A trimmed surface object to draw.                              M
  25. *                                                                            *
  26. * RETURN VALUE:                                                              M
  27. *   void                                                                     M
  28. *                                                                            *
  29. * KEYWORDS:                                                                  M
  30. *   IGDrawTrimSrf                                                            M
  31. *****************************************************************************/
  32. void IGDrawTrimSrf(IPObjectStruct *PObj)
  33. {
  34.     IPObjectStruct *PObjPolylines, *PObjCtlMesh, *PObjPolygons;
  35.     IPPolygonStruct *PPolylines, *PCtlMesh, *PPolygonTemp;
  36.  
  37.     if ((PObjPolylines = AttrGetObjectObjAttrib(PObj, "_isoline")) == NULL &&
  38.     IGGlblNumOfIsolines > 0) {
  39.     TrimSrfStruct *TrimSrf,
  40.         *TrimSrfs = PObj -> U.TrimSrfs;
  41.  
  42.     PObjPolylines = IPAllocObject("", IP_OBJ_POLY, NULL);
  43.     PObjPolylines -> Attrs = AttrCopyAttributes(PObj -> Attrs);
  44.     IP_SET_POLYLINE_OBJ(PObjPolylines);
  45.     for (TrimSrf = TrimSrfs; TrimSrf != NULL; TrimSrf = TrimSrf -> Pnext) {
  46.         int NumOfIso[2];
  47.  
  48.         NumOfIso[0] = -IGGlblNumOfIsolines;
  49.         NumOfIso[1] = -IGGlblNumOfIsolines;
  50.         PPolylines = IritTrimSrf2Polylines(TrimSrf, NumOfIso,
  51.                            IGGlblSamplesPerCurve,
  52.                            IGGlblPolylineOptiApprox,
  53.                            TRUE, TRUE);
  54.  
  55.         if (PPolylines != NULL) {
  56.         for (PPolygonTemp = PPolylines;
  57.              PPolygonTemp -> Pnext;
  58.              PPolygonTemp = PPolygonTemp -> Pnext);
  59.         PPolygonTemp -> Pnext = PObjPolylines -> U.Pl;
  60.         PObjPolylines -> U.Pl = PPolylines;
  61.         }
  62.     }
  63.     AttrSetObjectObjAttrib(PObj, "_isoline", PObjPolylines, FALSE);
  64.     }
  65.  
  66.     if (IGGlblDrawSurfacePoly || IGGlblDrawSolid) {
  67.     if ((PObjPolygons = AttrGetObjectObjAttrib(PObj, "_polygons"))
  68.                                     == NULL) {
  69.         fprintf(stderr,
  70.             "POLYGONIZATION OF TRIMMED SURFACE IS NOT SUPPORTED\n");
  71.         return;
  72.     }
  73.  
  74.     IGDrawPoly(PObjPolygons);
  75.     }
  76.     else if (PObjPolylines != NULL)
  77.         IGDrawPoly(PObjPolylines);
  78.  
  79.     if (IGGlblDrawSurfaceMesh) {
  80.     if ((PObjPolylines = AttrGetObjectObjAttrib(PObj, "_ctlmesh"))
  81.                                 == NULL) {
  82.         TrimSrfStruct *TrimSrf,
  83.         *TrimSrfs = PObj -> U.TrimSrfs;
  84.  
  85.         PObjCtlMesh = IPAllocObject("", IP_OBJ_POLY, NULL);
  86.         PObjCtlMesh -> Attrs = AttrCopyAttributes(PObj -> Attrs);
  87.         IP_SET_POLYLINE_OBJ(PObjCtlMesh);
  88.         for (TrimSrf = TrimSrfs;
  89.          TrimSrf != NULL;
  90.          TrimSrf = TrimSrf -> Pnext) {
  91.         PCtlMesh = IritTrimSrf2CtlMesh(TrimSrf);
  92.  
  93.         for (PPolygonTemp = PCtlMesh;
  94.              PPolygonTemp -> Pnext;
  95.              PPolygonTemp = PPolygonTemp -> Pnext);
  96.         PPolygonTemp -> Pnext = PObjCtlMesh -> U.Pl;
  97.         PObjCtlMesh -> U.Pl = PCtlMesh;
  98.         }
  99.         AttrSetObjectObjAttrib(PObj, "_ctlmesh", PObjCtlMesh, FALSE);
  100.     }
  101.  
  102.     IGDrawPoly(AttrGetObjectObjAttrib(PObj, "_ctlmesh"));
  103.     }
  104. }
  105.